package com.yiqi.lottery.feature.documentary.view;

import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.suozhang.framework.utils.T;
import com.yiqi.lottery.R;
import com.yiqi.lottery.common.widget.dialog.BottomBaseDialog;
import com.yiqi.lottery.common.widget.dialog.BounceBottomEnter;
import com.yiqi.lottery.common.widget.dialog.FlipVerticalSwingEnter;
import com.yiqi.lottery.entity.bo.HallBo;
import com.yiqi.lottery.entity.enums.CreateOrderType;
import com.yiqi.lottery.feature.home.view.PayActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class ShareBottomDialog extends BottomBaseDialog<ShareBottomDialog> {


    Context context;

    @BindView(R.id.tv_documentary_dialog_name)
    TextView tvDocumentaryDialogName;
    @BindView(R.id.tv_documentary_dialog_type)
    TextView tvDocumentaryDialogType;
    @BindView(R.id.tv_documentary_dialog_zigou)
    TextView tvDocumentaryDialogZigou;
    @BindView(R.id.tv_documentary_dialog_qigen)
    TextView tvDocumentaryDialogQigen;
    @BindView(R.id.tv_documentary_dialog_people)
    TextView tvDocumentaryDialogPeople;
    @BindView(R.id.tv_documentary_dialog_money)
    TextView tvDocumentaryDialogMoney;
    @BindView(R.id.tv_documentary_dialog_bili)
    TextView tvDocumentaryDialogBili;
    @BindView(R.id.btn_documentary_dialog_jian)
    LinearLayout btnDocumentaryDialogJian;
    @BindView(R.id.edt_documentary_dialog_beishu)
    EditText edtDocumentaryDialogBeishu;
    @BindView(R.id.btn_documentary_dialog_jan)
    RelativeLayout btnDocumentaryDialogJan;
    @BindView(R.id.btn_documentary_dialog_cancle)
    TextView btnDocumentaryDialogCancle;
    @BindView(R.id.btn_documentary_dialog_confrim)
    TextView btnDocumentaryDialogConfrim;
    private HallBo mHallBo;
    private int mPerNum;
    private int minAmount;

    private int mBet=1;
    public ShareBottomDialog(Context context, View animateView, boolean isInvited) {
        super(context, animateView);

        this.context = context;
    }


    public ShareBottomDialog(Context context, HallBo hallBo) {
        super(context);
        this.mHallBo = hallBo;
        this. mPerNum=hallBo.getBet_info().getPour_num();
    }

    @Override
    public View onCreateView() {

        showAnim(new BounceBottomEnter());
        View inflate = View.inflate(mContext, R.layout.dialog_gendan, null);
        ButterKnife.bind(this, inflate);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        if (mHallBo != null) {

            edtDocumentaryDialogBeishu.setText(mBet+"");
            tvDocumentaryDialogName.setText(mHallBo.getUser_info().getUsername());
            tvDocumentaryDialogType.setText(mHallBo.getPass_type());
            tvDocumentaryDialogZigou.setText(mHallBo.getOrder_amount()+"元");
            tvDocumentaryDialogQigen.setText(mHallBo.getMin_amount()+"元");;
            tvDocumentaryDialogPeople.setText(mHallBo.getFollow_num()+"人");
            minAmount=mHallBo.getMin_amount();
            tvDocumentaryDialogMoney.setText((mPerNum*2*mBet)+"元");
        }

        edtDocumentaryDialogBeishu.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
               if (!TextUtils.isEmpty(s.toString())){
                   mBet=Integer.valueOf(s.toString());
               }else {
                   mBet =0;
               }
                tvDocumentaryDialogMoney.setText((mPerNum*2*mBet)+"元");
            }
        });


    }

    @OnClick({R.id.btn_documentary_dialog_cancle, R.id.btn_documentary_dialog_confrim})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_documentary_dialog_cancle:
                dismiss();
                break;
            case R.id.btn_documentary_dialog_confrim:
                if (mBet>200000||mBet<1){
                    T.showShort("跟单倍数为1-200000倍！");
                    return;
                }

                Intent intent = new Intent(mContext, PayActivity.class);
                intent.putExtra("order_id", mHallBo.getOrder_id());
                intent.putExtra("multiple", mBet);
                intent.putExtra("order_type", CreateOrderType.GD.getIndex());
                intent.putExtra("total_amount", (mPerNum*2*mBet));
                mContext.startActivity(intent);
                dismiss();
                break;
        }
    }

    @OnClick({R.id.btn_documentary_dialog_jian, R.id.btn_documentary_dialog_jan})
    public void onViewMoneyClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_documentary_dialog_jian:
                if (mBet > 1) {
                    mBet--;
                }
                break;
            case R.id.btn_documentary_dialog_jan:
                mBet++;
                break;

        }
        edtDocumentaryDialogBeishu.setText(""+mBet);
        tvDocumentaryDialogMoney.setText((mPerNum*2*mBet)+"元");

    }
}